package com.wbao.dianniu.manager;

import java.util.LinkedList;

import com.wbao.dianniu.data.QaResponse;


public class QaDataChangeManager {
	private static LinkedList<IQaDataListener> mListener;
	public static QaDataChangeManager instance;

	public static QaDataChangeManager getInstance() {
		if (null == instance) {
			mListener = new LinkedList<IQaDataListener>();
			instance = new QaDataChangeManager();
		}
		return instance;
	}

	private QaDataChangeManager() {
	}
	
	public interface IQaDataListener {
		
		/**
		 * 新增一条数据更新
		 * 
		 * @param addData
		 */
		public void addOneData(QaResponse addData);
		
		/**
		 * 删除更新（By questId）
		 * 
		 * @param questId
		 */
		public void removeOneData(int questId);
		/**
		 * 点赞数更新
		 * 
		 * @param questId
		 * @param isGood
		 * @param goodCounts
		 */
		public void priseNotify(int questId,int isGood, int goodCounts);
		/**
		 * 回复数更新
		 * 
		 * @param questId
		 * @param answerCounts
		 */
		public void replyNotify(int questId,int answerCounts);
	}
	public void addQaChangeListener(IQaDataListener listener) {
		mListener.add(listener);
	}

	public void removeQaChangeListener(IQaDataListener listener) {
		mListener.remove(listener);
	}
	
	/**
	 * 	删除数据通知（通过ID）
	 * @param id
	 */
	public void notifyRemove(int questId) {
		for (int i = 0; i < mListener.size(); i++) {
			mListener.get(i).removeOneData(questId);
		}
	}
	
	/**
	 * 点赞数改变通知
	 */
	public void priseNotify(int questId,int isGood, int goodCounts){
		for (int i = 0; i < mListener.size(); i++) {
			mListener.get(i).priseNotify(questId, isGood, goodCounts);
		}
	}
	
	/**
	 * 回复数改变通知
	 */
	public void replyNotify(int questId,int answerCounts){
		for (int i = 0; i < mListener.size(); i++) {
			mListener.get(i).replyNotify(questId, answerCounts);
		}
	}
	
	public void addOneDataNotify(QaResponse addData) {
		for (int i = 0; i < mListener.size(); i++) {
			mListener.get(i).addOneData(addData);
		}
	}
	
}
